<%--
  Created by IntelliJ IDEA.
  User: caojian
  Date: 2017/3/10
  Time: 下午5:19
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="xmb" uri="http://xmb.suishoupai.com/tags" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>用户订单列表</title>
    <jsp:include page="common/common_css.jsp"/>
    <style>
        .border-left {
            border-left: 1px solid rgba(34, 36, 38, .1) !important;
        }
    </style>
</head>
<body>
<jsp:include page="common/header.jsp"/>
<div class="ui main container">
    <jsp:include page="common/message.jsp"/>
    <table class="ui celled padded table">
        <thead>
        <tr>
            <th class="center aligned">订单id</th>
            <th class="center aligned">用户id</th>
            <th class="center aligned">收货地址</th>
            <th class="center aligned">下单时间</th>
            <th class="center aligned">商品id</th>
            <th class="center aligned">商品名字</th>
            <th class="center aligned">购买数量</th>
            <th class="center aligned">状态</th>
        </tr>
        </thead>
        <tbody>
        <c:choose>
            <c:when test="${fn:length(ordersList.list) > 0}">
                <c:forEach items="${ordersList.list}" var="item">
                    <tr data-id="${item.orders.id}">
                    <td rowspan="${fn:length(item.goodsSnapshots)}"
                        class="center aligned">${item.orders.id}
                    </td>
                    <td rowspan="${fn:length(item.goodsSnapshots)}"
                        class="center aligned">
                            ${userId}
                    </td>
                    <td rowspan="${fn:length(item.goodsSnapshots)}"
                        class="center aligned">${item.orders.address}
                    </td>
                    <td rowspan="${fn:length(item.goodsSnapshots)}" class="center aligned">
                        <xmb:formatDate value="${item.orders.createTime}"/>
                    </td>
                    <c:set var="i" scope="session" value="0"/>
                    <c:forEach items="${item.goodsSnapshots}" var="goodsSnapshot">
                        <c:if test="${i>0}"><tr></c:if>
                        <td class="center aligned ${i>0?'border-left':''}">${goodsSnapshot.goodsId}</td>
                        <td class="center aligned">${goodsSnapshot.name}</td>
                        <td class="center aligned">${goodsSnapshot.count}</td>
                        <c:if test="${fn:length(item.goodsSnapshots)>1&&i==0}">
                            <td rowspan="${fn:length(item.goodsSnapshots)}" class="center aligned">
                                <c:choose>
                                    <c:when test="${item.orders.status==1}">
                                        代付款
                                    </c:when>
                                    <c:when test="${item.orders.status==2}">
                                        代发货
                                    </c:when>
                                    <c:when test="${item.orders.status==3}">
                                        已完成
                                    </c:when>
                                    <c:when test="${item.orders.status==4}">
                                        已关闭(${item.orders.description})
                                    </c:when>
                                    <c:otherwise>
                                        不认识的status
                                    </c:otherwise>
                                </c:choose>
                            </td>
                            </tr>
                        </c:if>
                        <c:if test="${i>0}"></tr></c:if>
                        <c:set var="i" scope="session" value="${i+1}"/>
                    </c:forEach>
                    <c:if test="${fn:length(item.goodsSnapshots)==1}">
                        <td rowspan="${fn:length(item.goodsSnapshots)}" class="center aligned">
                            <c:choose>
                                <c:when test="${item.orders.status==1}">
                                    代付款
                                </c:when>
                                <c:when test="${item.orders.status==2}">
                                    代发货
                                </c:when>
                                <c:when test="${item.orders.status==3}">
                                    已完成
                                </c:when>
                                <c:when test="${item.orders.status==4}">
                                    已关闭(${item.orders.description})
                                </c:when>
                                <c:otherwise>
                                    不认识的status
                                </c:otherwise>
                            </c:choose>
                        </td>
                    </c:if>
                    </tr>
                </c:forEach>
            </c:when>
            <c:otherwise>
                <tr>
                    <td class="center aligned" colspan="8">没有相关订单</td>
                </tr>
            </c:otherwise>
        </c:choose>
        </tbody>
        <tfoot>
        <tr>
            <th colspan="8" class="center aligned">
                <c:set var="pagination" scope="session" value="${ordersList}"/>
                <c:set var="paginationAction" scope="session" value="userBuy/${userId}/orders"/>
                <jsp:include page="common/page.jsp"/>
            </th>
        </tr>
        </tfoot>
    </table>
</div>

<jsp:include page="common/footer.jsp"/>
<jsp:include page="common/common_js.jsp"/>
<script>
    $(function () {
    });
</script>
</body>
</html>
